package com.bangbang.config;

import com.bangbang.job.TestJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class JobInit {

    @Autowired
    private Scheduler scheduler;

    //初始化
    @PostConstruct
    public void initjob() throws SchedulerException {

        JobDetail detail = JobBuilder.newJob(TestJob.class)
                .withIdentity("job2", "job")
                .build();

        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger2", "trigger")
                .startNow()
                /*.withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))*/
                .build();

        scheduler.scheduleJob(detail, trigger);
    }

}